package pl.bizuteria.sklep.server.request;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import pl.bizuteria.sklep.api.product.ICommonService;

import com.googlecode.objectify.Objectify;
import com.googlecode.objectify.ObjectifyService;

public class CommonService implements ICommonService {

	Logger logger = LoggerFactory.getLogger(CommonService.class);

	@Override
	public <T> T find(Class<? extends T> clazz, Long id) {
		logger.info("Find class: " + clazz + " with id: " + id);
		try {
			Objectify ofy = ObjectifyService.begin();
			T result = ofy.get(clazz, id);
			logger.info("Returned: " + result);
			return result;
		} catch (Exception e) {
			logger.info("Exception: " + e.getMessage());
			logger.info("Entity not found");
			return null;
		}

	}
}
